<?php

if ((!defined('NV_SYSTEM')) AND (!defined('NV_ADMIN'))) {
    Header("Location: ../index.php");
    exit;
}

global $db, $prefix, $multilingual, $currentlang;
if ($multilingual == 1) {
    $querylang = "WHERE planguage='$currentlang'";
} else {
    $querylang = "";
}
$sql = "SELECT * FROM ".$prefix."_nvvotings $querylang ORDER BY rand() DESC LIMIT 1";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$pollid = intval($row['pollid']);
$option = explode("|",$row['optiontext']);
$options = $row['options'];

if ($pollid == 0 || $pollid == "") {
    $content = "";
} else {
    $content = "<form action=\"".INCLUDE_PATH."modules.php?name=Voting\" method=\"post\">";
    $content .= "<input type=\"hidden\" name=\"pollid\" value=\"".$pollid."\">";
    $content .= "<font class=\"content\"><b>".$row['question']."</b></font><br><br>\n";
    $content .= "<table border=\"0\" width=\"100%\">";
 
    for($i=0;$i<=$options-1;$i++) {
	if(isset($options)) $options = $options."<br>";
    $content .= "<tr><td valign=\"top\"><input type=\"radio\" name=\"option_id\" value=\"$i\" class=\"content\">&nbsp;".$option[$i]."</td></tr>\n";
      }
    $content .= "<input type=\"hidden\" name=\"op\" value=\"pollvote\">";
    $content .= "</table><br><center><input class=\"button\" type=\"submit\" value=\""._VOTE."\"><br>";
    $content .= "<br><font class=\"content\"><a href=\"".INCLUDE_PATH."modules.php?name=Voting&amp;op=pollvote&amp;pollid=$pollid\"><b>"._RESULTS."</b></a><br><a href=\"".INCLUDE_PATH."modules.php?name=Voting\"><b>"._POLLS."</b></a><br>";
 
    if (($row['totalcomm'] !=0) || ($row['acomm']!=0)) {
	$content .= "<br>"._VOTES.": <b>".$row['totalvotes']."</b><br> "._PCOMMENTS." <b>".$row['totalcomm']."</b>\n\n";
    } else {
	$content .= "<br>"._VOTES." <b>".$row['totalvotes']."</b>\n\n";
    }
    $content .= "</font></center></form>\n\n";
}

?>